/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Datos;

import java.awt.event.KeyEvent;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author RODRIGO
 */
public class Global {

    public static float costoTotalSimple = 0;
    public static float valorTotalSimple = 0;
    public static float costoTotalComplem = 0;
    public static float valorTotalComplem = 0;
    
    public static void limpiarTabla(JTable tabla) {
        DefaultTableModel modelo = (DefaultTableModel) tabla.getModel();
        modelo.setNumRows(0);
    }

    public static void validarLetra(int lim, java.awt.event.KeyEvent evt, JTextField t) {

        int k = (int) evt.getKeyChar();
        if (k > 47 && k < 58) {
            evt.setKeyChar((char) KeyEvent.VK_CLEAR);
        }
        if (k == 10) {
            t.transferFocus();
        }
        if (t.getText().length() >= lim) {
            evt.setKeyChar((char) KeyEvent.VK_CLEAR);
        }
    }

    public static void validarNumero(int lim, java.awt.event.KeyEvent evt, JTextField t) {
        int k = (int) evt.getKeyChar();
        if (k >= 97 && k <= 122 || k >= 65 && k <= 90) {//Si el caracter ingresado es una letra
            evt.setKeyChar((char) KeyEvent.VK_CLEAR);

        }
        if (k == 241 || k == 209) {//Si es ñ
            evt.setKeyChar((char) KeyEvent.VK_CLEAR);
        }
        if (k == 10) {
            t.transferFocus();
        }
        if (t.getText().length() >= lim) {
            evt.setKeyChar((char) KeyEvent.VK_CLEAR);
        }
    }
    
    public static String enFormato(String cadena){
        String cad=""+Character.toUpperCase(cadena.charAt(0));
        for (int i=1;i<cadena.length();i++){
            cad=cad+Character.toLowerCase(cadena.charAt(i));
        }
        return cad;
    }
}
